package com.ultron.app.controller;

import com.aizuda.bpm.engine.FlowLongEngine;
import com.aizuda.bpm.engine.core.FlowCreator;
import com.ultron.app.entity.system.Result;
import com.ultron.app.modules.system.entity.sysDic.bo.SysDicBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 标题：FlowLongController
 * 说明：
 * 时间：2025/10/10
 * 作者：nljlhq
 */
@RestController
@CrossOrigin
@RequestMapping("/api/ultron/system/flowlong")
@Api(value = "FlowLongController", tags = "流程引擎API")
public class FlowLongController {

    @Autowired
    private FlowLongEngine flowLongEngine;

    protected static FlowCreator testCreator = FlowCreator.of("test001", "测试001");


    @PostMapping(value = "/deploy")
    @ApiOperation("部署流程API")
    public Result<Long> deploy() {
        // 返回 流程定义ID 用于后续发起流程实例
        Long processId = flowLongEngine.processService().deployByResource("flowLong/process.json", testCreator, false);
        return Result.success(processId);
    }

    @PostMapping(value = "/startInstanceById")
    @ApiOperation("启动流程API")
    public Result startInstanceById() {
        Map<String, Object> args = new HashMap<>();
        args.put("day", 8);
        flowLongEngine.startInstanceById(1976634222628487169L, testCreator, args).ifPresent(instance -> {
            // 其它流程操作
        });
        return Result.success(true);


    }


}
